<?php  

/**
* 
*/
abstract class BaseTableField
{
  
  protected $_value;
  protected $_validationError;
  protected $_size;
  protected $_defaultValue;
  protected $_notNull = true;
  protected $_name;
  protected $_type;
  
  protected $_table;
  public function setTable($table){
    $this->_table = $table;
  }
  public function getTable(){
    return $this->_table;
  }
  public function getValidationError(){
    return $this->_validationError;
  }
  public function __construct($name, $options=array())
  {
    $this->_name = $name;
    $this->_initialize($options);
  }
  
  protected function _initialize($options){
    foreach ($options as $key => $option) {
      switch ($key) {
        case 'size':
          $this->_size = $option;
          break;
        case 'defaultValue':
          $this->_defaultValue = $option;
          break;
        case 'notNull':
          $this->_notNull = (boolean)$option;
          break;
        default:
          break;
      }
    }
  }
  
  public function isValid(){
    return $this->_validationError==null;
  }
  
  public function getName(){
    return $this->_name;
  }
  
  public function getValue(){
    return $this->_value;
  }
  
  abstract function setValue($value);
  
  function generateCreateScript(){
    return '`'.$this->_name.'` '.$this->_type.'('.$this->_size.')'.($this->_notNull==true ? ' NOT NULL ' : ' ');
  }
}


?>